<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Todo List</title>
    <style>
        .task-item {
            display: flex;
            align-items: center;
            margin-bottom: 5px;
        }
        .task-item span {
            flex: 1;
        }
        .delete-btn {
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <h2>Todo List</h2>
    <input type="text" id="taskInput" placeholder="输入新任务">
    <button id="addButton">添加任务</button>
    <div id="taskList"></div>

    <script>
        const addButton = document.getElementById('addButton');
        const taskInput = document.getElementById('taskInput');
        const taskList = document.getElementById('taskList');

        addButton.addEventListener('click', function () {
            const taskText = taskInput.value.trim();
            if (taskText !== '') {
                const taskItem = document.createElement('div');
                taskItem.classList.add('task-item');
                taskItem.innerHTML = `<span>${taskText}</span><button class="delete-btn">删除</button>`;
                taskList.appendChild(taskItem);
                taskInput.value = '';

                const deleteButton = taskItem.querySelector('.delete-btn');
                deleteButton.addEventListener('click', function () {
                    taskList.removeChild(taskItem);
                });
            }
        });
    </script>
</body>
</html>